package com.roocon.thread.net;

import java.util.concurrent.atomic.LongAdder;

public class LongAdderTest {
  static java.util.concurrent.atomic.LongAdder count = new LongAdder();

  static class AddThread implements Runnable {

    @Override
    public void run() {
      for (int i = 0; i < 8; i++) {
        count.increment();
        System.out.println("name:\t" + Thread.currentThread().getName() +"\tlongValue:" + count.longValue());
        try {
          Thread.sleep(500);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }

  public static void main(String[] args) throws InterruptedException {
    Thread t1 = new Thread(new AddThread());
    Thread t2 = new Thread(new AddThread());
    t1.start();
    t2.start();
    System.out.println("t1.join ------------------");
    t1.join();
    //t2.join();
    //System.out.println(count.intValue() == 200000);
  }
}
